package cn.tedu.ivos.dict.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.mapper.DictMapper;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/v1/dict")
public class DictController {
    @Autowired
    private DictService dictService;
    @GetMapping("select")
    public JsonResult select(DictQuery dictQuery){
        log.debug("{}",dictQuery);
        List<DictVO> dictVOList = dictService.select(dictQuery);
        return JsonResult.ok(dictVOList);
    }
    @PostMapping("save")
    public JsonResult save(@RequestBody DictSaveParam dictSaveParam){
        log.debug("{}",dictSaveParam);
         dictService.save(dictSaveParam);
        return JsonResult.ok();
    }
    /**
     * 数据回写
     */
    @GetMapping("selectById")
    public JsonResult selectById(DictQuery dictQuery){
        log.debug("{}",dictQuery);
        List<DictVO> dictVOList = dictService.select(dictQuery);
        return JsonResult.ok(dictVOList);
    }
    /**
     * 删除方法
     */
    @PostMapping("delete")
    public JsonResult delete(DictSaveParam dictSaveParam){
        log.debug("{}",dictSaveParam);
        dictService.delete(dictSaveParam);
        return JsonResult.ok();
    }
}
